$(function(){
	initView();
	bindFun();
})
function initView(){
	//全部产品调用数据
	var params = {};	
	params.age=Number(getQueryString("age"));
	params.appBase=JSON.parse(sessionStorage.appBase);
		padMarketing.ajaxNormal('/pad_marketing/main/appGetPackages.action',params,	
		function(data) {
			//健康H  
			for(var i in data) {
				if(data[i].category=="H"){
					if(data[i].allowSaling==true){
						var pag1 = $('<li class="thumbnail"  category="'+data[i].category+'"  productId="'+data[i].productId+'"><img src="/portal/resources/images/product/packages/'+ data[i].pkgId  +'/ALL.jpg" alt="..."><div class="caption" data-app=\''+JSON.stringify(data[i])+'\'><h3 class="font-16 p-overflow">' + data[i].title + '</h3><p class="font-14 gray">' + data[i].subTitle + '</p></div><div onclick="checkSelect(this)" class="check-list default"><input data-pkg=\''+JSON.stringify(data[i])+'\' type="checkbox"><label for="">&nbsp;</label></div></li>');
						
					}else{
						var pag1 = $('<li class="thumbnail"  category="'+data[i].category+'"  productId="'+data[i].productId+'"><img src="/portal/resources/images/product/packages/'+ data[i].pkgId  +'/ALL.jpg" alt="..."><div class="caption" data-app=\''+JSON.stringify(data[i])+'\'><h3 class="font-16 p-overflow">' + data[i].title + '</h3><p class="font-14 gray">' + data[i].subTitle + '</p></div><div  class="check-list default disabled"><input disabled data-pkg=\''+JSON.stringify(data[i])+'\' type="checkbox"><label for="">&nbsp;</label></div></li>');
						
					}
					$('#health').append(pag1);
				}
				
			}
			//退休R
			for(var j in data) {
				if(data[j].category=="R"){
					if(data[j].allowSaling==true){
						var pag2 = $('<li class="thumbnail"  category="'+data[j].category+'" productId='+data[j].productId+'><img src="/portal/resources/images/product/packages/'+ data[j].pkgId  +'/ALL.jpg" alt="..."><div class="caption" data-app=\''+JSON.stringify(data[j])+'\'><h3 class="font-16 p-overflow">' + data[j].title + '</h3><p class="font-14 gray">' + data[j].subTitle + '</p></div><div onclick="checkSelect(this)" class="check-list default"><input data-pkg=\''+JSON.stringify(data[j])+'\' type="checkbox"><label for="">&nbsp;</label></div></li>');
						
					}else{
						var pag2 = $('<li class="thumbnail"  category="'+data[j].category+'" productId='+data[j].productId+'><img src="/portal/resources/images/product/packages/'+ data[j].pkgId  +'/ALL.jpg" alt="..."><div class="caption" data-app=\''+JSON.stringify(data[j])+'\'><h3 class="font-16 p-overflow">' + data[j].title + '</h3><p class="font-14 gray">' + data[j].subTitle + '</p></div><div class="check-list default disabled"><input disabled data-pkg=\''+JSON.stringify(data[j])+'\' type="checkbox"><label for="">&nbsp;</label></div></li>');
						
					}
					$('#old').append(pag2);
				}
			}
			//子女教育E
			for (var k in data) {
				if(data[k].category=="E"){
					if(data[k].allowSaling==true){
						var pag3 = $('<li class="thumbnail" category="'+data[k].category+'" productId='+data[k].productId+'><img src="/portal/resources/images/product/packages/'+ data[k].pkgId  +'/ALL.jpg" alt="..."><div class="caption" data-app=\''+JSON.stringify(data[k])+'\'><h3 class="font-16 p-overflow">' + data[k].title + '</h3><p class="font-14 gray">' + data[k].subTitle + '</p></div><div onclick="checkSelect(this)" class="check-list default"><input  data-pkg=\''+JSON.stringify(data[k])+'\' type="checkbox"><label for="">&nbsp;</label></div></li>');
						
					}else{
						var pag3 = $('<li class="thumbnail" category="'+data[k].category+'" productId='+data[k].productId+'><img src="/portal/resources/images/product/packages/'+ data[k].pkgId  +'/ALL.jpg" alt="..."><div class="caption" data-app=\''+JSON.stringify(data[k])+'\'><h3 class="font-16 p-overflow">' + data[k].title + '</h3><p class="font-14 gray">' + data[k].subTitle + '</p></div><div  class="check-list default disabled"><input  disabled data-pkg=\''+JSON.stringify(data[k])+'\' type="checkbox"><label for="">&nbsp;</label></div></li>');
						
					}
					$('#edu').append(pag3);
				}	
			}
			//財富F
			for (var l in data) {
				if(data[l].category=="F"){
					if(data[l].allowSaling==true){
						var pag5 = $('<li class="thumbnail"  category="'+data[l].category+'" productId="'+data[l].productId+'"><img src="/portal/resources/images/product/packages/'+ data[l].pkgId  +'/ALL.jpg" alt="..."><div class="caption" data-app=\''+JSON.stringify(data[l])+'\'><h3 class="font-16 p-overflow">' + data[l].title + '</h3><p class="font-14 gray">' + data[l].subTitle + '</p></div><div onclick="checkSelect(this)" class="check-list default"><input  data-pkg=\''+JSON.stringify(data[l])+'\' type="checkbox"><label for="">&nbsp;</label></div></li>');
						
					}else{
						var pag5 = $('<li class="thumbnail"  category="'+data[l].category+'" productId="'+data[l].productId+'"><img src="/portal/resources/images/product/packages/'+ data[l].pkgId  +'/ALL.jpg" alt="..."><div class="caption" data-app=\''+JSON.stringify(data[l])+'\'><h3 class="font-16 p-overflow">' + data[l].title + '</h3><p class="font-14 gray">' + data[l].subTitle + '</p></div><div  class="check-list default disabled"><input disabled data-pkg=\''+JSON.stringify(data[l])+'\' type="checkbox"><label for="">&nbsp;</label></div></li>');
						
					}
					$('#plan').append(pag5);
				}
				
			}
			//旅遊L
			for (var m in data) {
				if(data[m].category=="L"){
					if(data[m].allowSaling==true){
						var pag4 = $('<li class="thumbnail"  category="'+data[m].category+'" productId="'+data[m].productId+'"><img src="/portal/resources/images/product/packages/'+ data[m].pkgId  +'/ALL.jpg" alt="..."><div class="caption" data-app=\''+JSON.stringify(data[m])+'\'><h3 class="font-16 p-overflow">' + data[m].title + '</h3><p class="font-14 gray">' + data[m].subTitle + '</p></div><div onclick="checkSelect(this)" class="check-list default"><input  data-pkg=\''+JSON.stringify(data[m])+'\' type="checkbox"><label for="">&nbsp;</label></div></li>');
						
					}else{
						var pag4 = $('<li class="thumbnail"  category="'+data[m].category+'" productId="'+data[m].productId+'"><img src="/portal/resources/images/product/packages/'+ data[m].pkgId  +'/ALL.jpg" alt="..."><div class="caption" data-app=\''+JSON.stringify(data[m])+'\'><h3 class="font-16 p-overflow">' + data[m].title + '</h3><p class="font-14 gray">' + data[m].subTitle + '</p></div><div  class="check-list default disabled"><input disabled data-pkg=\''+JSON.stringify(data[m])+'\' type="checkbox"><label for="">&nbsp;</label></div></li>');
						
					}
					$('#life').append(pag4);
				}	
			}			
		},
		function(){
			
		}
	);
}
function bindFun(){
	$("#returnBack").click(function(){
		window.location.href="/pad_marketing/order/index.action";
	});
	$("#returnBac").click(function(){
		window.location.href="/pad_marketing/order/index.action";
	});
	$("#complete").click(function(){
		var arr =$(".thumbnail input[checked='checked']");
		if(arr.length==0){
			alertMsg("请您勾选产品");
			return;
		}
		var obj={};
		var productId=$(".thumbnail input[checked='checked']").parent().parent().attr("productId");	
		if(sessionStorage.appBase){
			var appBase = JSON.parse(sessionStorage.appBase);
			obj.appId = appBase.appId;
			obj.orderId = appBase.orderId;
			obj.sign = appBase.sign;
		}else{
			console.log('appBase参数不存在,无法提交完成！！！');
			return;
		}
		obj.productId=productId;
		
		padMarketing.ajaxNormal(
				"/pad_marketing/main/chgProductBody.action",
				obj,
				function (data){
					
					window.location.href="/pad_marketing/order/index.action";				
				},
				function(data){}
		);
	})
}
function checkSelect(obj){
	$(".thumbnail input[checked='checked']").attr("checked",false);
	$(obj).find("input").attr("checked",true);
}
$(document).on('click','.thumbnail',function(){
	$(".tabs-line a").eq(0).addClass("active").siblings().removeClass("active");
	$("#open4 .tabSwiper .swiper-wrapper .swiper-slide").eq(0).addClass("swiper-slide-active").siblings().removeClass("swiper-slide-active");
	$("#open4 .tabSwiper .swiper-wrapper").css({"transform":" translate3d(0px, 0px, 0px)","transition-duration": "0 s"});
	var ob = JSON.parse($(this).find('.caption').attr("data-app"));	
	var params = {};
	params.pkgId = ob.pkgId;
	params.sign = ob.sign;
	padMarketing.ajaxNormal(
		'/pad_marketing/main/type003getDecall.action',
		params,
		function(data){
			
			$("#title").html(data.title+" (投保年龄："+data.subTitle+")");
			$("#benefit").html(data.benefit);
			$("#feature").html(data.feature);
			$("#featureimg").attr("src","/portal/resources/images/product/packages/"+ data.pkgId +"/CPTS.jpg");
			$("#benefitimg").attr("src","/portal/resources/images/product/packages/"+ data.pkgId +"/LYJJ.jpg");
			$("#demoImg").attr("src","/portal/resources/images/product/packages/"+ data.pkgId +"/TBSL.jpg");
		},
		function(data){
			
		}
	);
	showDiv('open4');
})
$(document).on('click','.check-list',function(event){
	 event.stopPropagation();
})

$(document).on('click','input',function(){
	var slide = $(".check-list  input:checkbox:checked").attr('data-pkg');		
	var obj = JSON.parse(slide);
	if(obj.allowSaling){		
		
	}else{
		$(".check-list  input").attr('info','1');
		alertMsg('此产品不可购买');
			$('#alertMsg_btn3').click(function(){
				$('input[info="1"]').prop("checked",false);
			})		
	}
})
